package dao;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import utility.Util_Trading;
import databean.ItemBean;

public class GetMyeBaySellingDAO {

	public static List<ItemBean> getMyeBaySelling() {
		Document response = Util_Trading.sendRequest("GetMyeBaySelling.txt", null);
		
		NodeList ids=response.getElementsByTagName("ItemID");
		int len=ids.getLength();
		
		NodeList titles=response.getElementsByTagName("Title");
		NodeList prices=response.getElementsByTagName("CurrentPrice");
		NodeList urls=response.getElementsByTagName("ViewItemURL");
		NodeList quantitys=response.getElementsByTagName("Quantity");
		
		List<ItemBean> items = new ArrayList<ItemBean>();
		
		for(int i=0;i<len;i++){
			ItemBean item=new ItemBean();
			item.setItemID(geti(ids,i));
			item.setTitle(geti(titles,i));
			item.setCurrentPrice(geti(prices,i));
			item.setViewItemURL(geti(urls,i));
			item.setQuantity(geti(quantitys,i));
			items.add(item);
		}
		return items;
	}
    private static String geti(NodeList list,int i){
    	return list.item(i).getChildNodes()
		.item(0).getNodeValue();
    }
}
